﻿using System;
using System.Collections.Generic;
using System.Configuration;
using Framework.Data;
using Framework.Core;

namespace Framework
{
    /// <summary>
    /// 租户上下文类
    /// </summary>
    public static class TenantContext
    {
        private static ITenantContextProvider _provider;

        /// <summary>
        /// 需要被调用一次，用来注册相应的 TenantContextProvider
        /// </summary>
        /// <param name="provider"></param>
        public static void SetTenantContextProvider(ITenantContextProvider provider)
        {
            _provider = provider;
        }

        /// <summary>
        /// 租户唯一标识
        /// </summary>
        public static string TenantKey
        {
            get
            {
                string tenantKey = _provider.TenantKey;
                return tenantKey;
            }
        }

        /// <summary>
        /// 租户界面语言
        /// </summary>
        public static string Language
        {
            get { return _provider.Language.ToLower(); }
        }

        ///// <summary>
        ///// 租户里的所有酒店
        ///// </summary>
        //public static List<HotelOrg> Hotels 
        //{
        //    get { return null; }
        //}

        /// <summary>
        /// 第一期里假设每个酒店就是一个租户，对应分库一个数据库
        /// </summary>
        public static HotelOrg CurrentHotel { get; set; }

        /// <summary>
        /// The DB Connection String of the tenant.
        /// </summary>
        public static string DbConnectionString
        {
            get { return ConnectionHelper.HiveMapCollection.Find(s => s.OrgId == CurrentHotel.HotelOrgId).ConnectionString; }
        }
    }
}